<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ActiveForm;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $model common\models\Check */
/* @var $check_model common\models\CheckLog */
/* @var $check_list common\models\CheckLog[] */
/* @var $form yii\widgets\ActiveForm */

$this->title = '申请审核';
$this->params['breadcrumbs'][] = ['label' => '申请审核', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

\backend\assets\ViewerAsset::register($this);
\backend\assets\LayerAsset::register($this);!
$js = <<<JS
$('.images').viewer();
$('#check_list').click(function(){
    layer.open({
      type: 1,
      skin: 'layui-layer-rim', //加上边框
      title: '审核记录',
      area: ['800px', '500px'], //宽高
      content: $('.check-list').html()
    });
});
JS;

$this->registerJs($js);
$css = <<<CSS
.images {
    height: 300px;
    list-style:none;
}
.images li {
    float: left;
    position: relative;
    width: 200px;
    height: 200px;
    margin-right: 15px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
}
.images li img {
    max-height: 250px;
}
CSS;
$this->registerCss($css);
?>


<div class="box">
    <div class="box-header">
        <div class="btn-group">
            <?= Html::a('<i class="fa fa-list-ol"></i>', false, ['class' => 'btn btn-default', 'id' => 'check_list']) ?>
            <!-- /.btn-group -->
        </div>
        <div class="pull-right">
            <?= Html::a('<i class="fa fa-reply"></i>', ['index'], ['class' => 'btn btn-default']) ?>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body no-padding">
        <?= DetailView::widget([
            'model' => $model,
            'attributes' => [
                'id',
                [
                    'attribute' => 'user_id',
                    'value' => $model->user->realname ?: $model->user->username,
                ],
                'check_time:datetime',
                [
                    'attribute' => 'created_at',
                    'label' => '申请时间',
                    'value' => date('Y-m-d H:i:s', $model->created_at),
                ],
                [
                    'attribute' => 'bl_img',
                    'format' => 'raw',
                    'value' => function($model){
                        $str = '<ul class="images">';
                        /** @var \common\models\Check $model */
                        foreach($model->files as $k => $v){
                            $str .= '<li>'.Html::img($v->file_path, ['width' => '200', 'max-height' => '250px']). '</li>';
                        }
                        $str .= '</ul>';
                        return $str;
                    }
                ]
            ],
        ]) ?>

    </div>
    

    <div class="box-body">
        <?php $form = ActiveForm::begin([
            'options'=>['class'=>'form-horizontal'],
            'fieldConfig'=>[
                'template'=>"{label}\n<div class=\"col-sm-10\">{input}\n{hint}\n{error}</div>",
                'labelOptions'=>['class'=>'col-sm-2 control-label'],
            ],
        ]); ?>
        
        <?= $form->field($check_model, 'remark')->textarea(['style' => 'width:250px', 'cols' => 30, 'rows' => 4, 'readonly'=> $check_model->primaryKey ]) ?>
        <?php
            if($check_model->primaryKey == null) {
                echo $form->field($check_model, 'status')->dropDownList(['' => '请选择', '1' => '不通过', '2' => '通过'], ['style' => 'width: 250px']);
            }else{
                echo $form->field($check_model, 'remark')->label('状态')->textInput(['readonly' => true, 'style' => 'width:250px', 'value' => $check_model->status == 1 ? '不通过' : '通过']);
            }
        ?>

        <?php
            if( $check_model->primaryKey == null ){
                ?>
                <div class="box-footer">
                    <a href="javascript:history.back();" class="btn btn-default">取消</a>
                    <?= Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success pull-right' : 'btn btn-primary pull-right']) ?>
                </div>
                <?php
            }
        ?>
        
        <?php ActiveForm::end(); ?>

    </div>
    <!-- /.box-body -->
</div>

<scction class="check-list" style="display: none">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <!-- Check all button -->
                    <!-- /.btn-group -->
                    <!-- /.pull-right -->
                </div>

                <!-- /.box-header -->
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'layout' => "<div class=\"box-body table-responsive\">{items}</div>\n<div class=\"box-footer clearfix\"><div class=\"row\"><div class=\"col-xs-12 col-sm-7\"></div></div></div>",
                    'tableOptions'=>['class'=>'table table-bordered table-hover'],
                    'filterModel'=>null,
                    'pager'=>[
                        'class'=>'yii\widgets\LinkPager',
                        'options' => [
                            'class' => 'pagination pagination-sm no-margin',
                        ],
                    ],
                    'columns' => [
                        'id',
                        [
                            'attribute' => 'admin_id',
                            'value' => function($model){
                                /** @var \common\models\checklog $model */
                                return $model->adminUser->username;
                            }
                        ],
                        [
                            'attribute' => 'admin_group',
                            'value' => function($model){
                                /** @var \common\models\checklog $model */
                                return $model->adminUser->group;
                            }
                        ],
                        'remark',
                        [
                            'attribute' => 'status',
                            'value' => function($model){
                                return $model->status == 1 ? '未通过' : '已通过';
                            }
                        ],
                        [
                            'attribute' => 'created_at',
                            'format' => ['date', 'php:Y-m-d H:i:s'],
                        ],
                    ],
                ]); ?>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    </div>
</scction>

